class Foot{
    constructor(){
        this.url = "http://localhost:3000/api";
        this.cont = document.querySelector(".container");
        this.getLocal()
        this.load()
    }
    load(){
        ajax({
            url:this.url,
            data:{
                type:"getGoods"
            },
            success:res=>{
                this.res=JSON.parse(res).msg
                this.render()
            }
        })
    }
    getLocal(){
        this.goods = localStorage.getItem("goods") ? JSON.parse(localStorage.getItem("goods")) : []
    }
    render(){
        let str = ""
        this.res.forEach(val1=>{
            this.goods.forEach(val2=>{
                if(val1.proId===val2.id){
                    str +=
                            `<div class="box" index="${val2.id}">  
                            <a href="../detail.html?id=${val2.id}" class="box_a" target="blank">
                                    <div class="pic">
                                        <img src="${val1.img}" alt="">
                                    </div>
                                    <div class="info">
                                        <p class="name">${val1.proName}</p>
                                        <p class="price">建议零售价：￥<span>${val1.price}</span></p>
                                    </div></a>
                                    <input type="button" class="add" value="加入购物车">
                                </div>`
                }
            })
        })
        this.cont.innerHTML = str;
        console.log(str)
    }
}
new Foot()